import React, { useMemo } from 'react';
import Render, { usePage } from 'schema-render';
import { renderWidgets } from '../../widgets';
import { Empty } from 'antd';

const PageView: React.FC<{}> = () => {
  const handle = usePage();
  const schema = useMemo(() => {
    const schemaStr = localStorage.getItem('tk-json-schema') || '';

    return JSON.parse(schemaStr);
  }, []);

  console.log(schema);

  if (!localStorage.getItem('tk-json-schema')) return <Empty description="请设置页面schema数据" />;

  return <Render schema={schema} handle={handle} widgets={{ ...renderWidgets }} />;
};

export default PageView;
